package cn.kgc.car.dao;

import cn.kgc.car.entity.Car;
import cn.kgc.car.entity.User;
import cn.kgc.car.service.UserOpera;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.*;

public class Init {
    public static Map<Integer, Car> carMap=new HashMap<>();
    public static List<User> users=new ArrayList<>();
    public static File file=new File("user.txt");
    /**
     * 初始化5条汽车信息
     */
    static {
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
        Car car1=new Car(1,"奔驰",10,"奔驰glc",0,"白色",5000,new Date());
        Car car2=new Car(2,"宝马",15,"宝马x3",1,"黑色",6000,new Date());
        Car car3=new Car(3,"奥迪",5,"奥迪a4",0,"红色色",4000,new Date());
        Car car4=new Car(4,"法拉利",20,"法拉利488",0,"黄色",8000,new Date());
        Car car5=new Car(5,"大众",8,"途锐",1,"黑色",3000,new Date());
        carMap.put(car1.getNum(),car1);
        carMap.put(car2.getNum(),car2);
        carMap.put(car3.getNum(),car3);
        carMap.put(car4.getNum(),car4);
        carMap.put(car5.getNum(),car5);
    }

    /**
     * 初始化3个用户信息
     */
    static {
        User user1=new User("李爽","123456");
        User user2=new User("admin","123456");
        User user3=new User("张三","123456");
        users.add(user1);
        users.add(user2);
        users.add(user3);
        if (file.length() <= 0){
            UserOpera.Seria(users,file);
        } else {
            users = UserOpera.unSeria(file);
        }

    }
}
